package com.book.dao;

import com.book.bean.Book;
import com.book.utils.BaseDao;

import java.util.List;

public class BookDao extends BaseDao<Book> {
    public List<Book> selectAll(){
        String sql = "select * from book";
        return queryAll(sql,Book.class);
    }
    public int addBook(Book book){
        String sql = "insert into book(bname,bprice,bauthor,bdesc)values(?,?,?,?)";
        return adu(sql,book.getBname(),book.getBprice(),book.getBauthor(),book.getBdesc());
    }
    public Book findById(int bid){
        String sql = "select * from book where bid = ?";
        return queryOne(sql,Book.class,bid);
    }
    public int updateBook(Book book){
        String sql = "update book set bname=?,bprice=?,bauthor=?,bdesc=? where bid=?";
        return adu(sql,book.getBname(),book.getBprice(),book.getBauthor(),book.getBdesc(),book.getBid());
    }
    public int deleteBook(int bid){
        String sql ="delete from book where bid = ?";
        return adu(sql,bid);
    }
}
